package com.zqxq.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;

import net.sf.json.JSONObject;

import com.google.gson.JsonObject;
import com.zqxq.util.*;

public class LoginAPI {
	static List<NameValuePair> data = new ArrayList<NameValuePair>();
	
	
	public static JsonObject Login(String url,String phone,String passwd) 
	{
		JsonObject Result = null;
		//List<NameValuePair> data = new ArrayList<NameValuePair>();
		data.add(new BasicNameValuePair("phone", phone));
        data.add(new BasicNameValuePair("login_pwd", passwd));
        //请求实体排序
        paramSort ps = new paramSort();
        String paramsort = ps.sortParam(data);
        //生成签名
        Signature sign = new Signature();
        Map<String, String> signstr = sign.signatureBuild(paramsort);
        String signature = signstr.get("signature");
        String timestamp = signstr.get("timestamp");
		Result = HttpClientHelper.getJSONObjectByPost(url, data,signature,timestamp);
		return Result;
		
	}

	public static HttpClient Login(HttpClientHelper httphelper) throws IOException {
		// TODO Auto-generated method stub
		//JSONObject Result = null;
		HttpClient httpclient = HttpClients.createDefault();
		httpclient = HttpClientHelper.Login(httphelper);
		return httpclient;
	}

	

	
}